<?php

namespace Beerus\Modules\DesignerAdv\Actions;

use Doraemon\cache\Queue;
use Doraemon\model\KaManage\KaDesignerMatter;
use Doraemon\model\KaManage\KaDesignerPerch;
use Encore\Admin\Actions\RowAction;
use Illuminate\Http\Request;

class HadUpload extends RowAction
{
	public $name = '已上传';
	const TOAST_ALERT = '是否已经在frieza配置了该广告？';

	public function handle($id) {
		$result = KaDesignerMatter::update([
			'data_status' => KaDesignerMatter::STATUS_APPROVE,
		], [
			'id' => $id
		]);

		if ($result) {
			$matter_info = KaDesignerMatter::get('*', [
				'id' => $id
			]);

			if ($matter_info['type'] == KaDesignerPerch::SEARCH_RESULT) {
				Queue::insertQueue('queue/Resource/Sync', [
					'perch_id' => $matter_info['perch_id']
				], Queue::QUEUE_DORAEMON);
			}

			return $this->response()->success('审核通过成功(＾－＾)V')->refresh();
		}else{
			return $this->response()->success('审核通过失败,请稍后重试o(TωT)o');
		}
	}

	public function retrieveModel(Request $request)
	{
		if (!$key = $request->get('_key')) {
			return false;
		}

		return $key;
	}

	public function dialog()
	{
		$this->confirm(self::TOAST_ALERT);
	}
}
